﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace BiessesXmlReader
{
    public class Part
    {
        public int SizeNo { get;private  set; }
        public string InfoDraw_1 { get;private  set; }
        public string InfoDraw_2 { get;private  set; }
        public string InfoDraw_3 { get;private  set; }
        public string InfoDraw_4 { get;private  set; }
        public string Draw_1 { get;private  set; }
        public string Draw_2 { get;private  set; }
        public string Draw_3 { get;private  set; }
        public string Draw_4 { get;private  set; }
        public string CabDesc { get;private  set; }
        public double CabDepth { get;private  set; }
        public double CabHeigth { get;private  set; }
        public string MatEdgeR { get;private  set; }
        public string MatEdgeL { get;private  set; }
        public string MatEdgeLo { get;private  set; }
        public string MatEdgeUp { get;private  set; }
        public string Material { get;private  set; }
        public string Desc1 { get;private  set; }
        public string Desc2 { get;private set; }
        public string IDesc { get;private  set; }
        public string IIDesc { get;private  set; }
        public int MatNo { get;private  set; }
        public string Code { get;private set; }
        public string Grian { get;private set; }
        public string qMin { get;private set; }
        public double L { get;private set; }
        public double W { get;private set; }
        public string id { get;private set; }
        public static List<Part> GetParts(XElement x)
        {
            List<Part> Parts = new List<Part>();
            List<XElement> XP = x.Elements("Part").ToList();
            foreach (var xp in XP)
            {
                Part p = new Part();
                p.id = (xp.Attribute("id") == null) ? string.Empty : xp.Attribute("id").Value;
                p.L = (xp.Attribute("L") == null) ? 0 : double.Parse(xp.Attribute("L").Value);
                p.W = (xp.Attribute("W") == null) ? 0 : double.Parse(xp.Attribute("W").Value);
                p.qMin = (xp.Attribute("qMin") == null) ? string.Empty : xp.Attribute("qMin").Value;
                p.Grian = (xp.Attribute("Grain") == null) ? string.Empty : xp.Attribute("Grain").Value;
                p.Code = (xp.Attribute("Code") == null) ? string.Empty : xp.Attribute("Code").Value;
                p.MatNo = (xp.Attribute("MatNo") == null) ? 0 : int.Parse(xp.Attribute("MatNo").Value);
                p.IDesc = (xp.Attribute("IDesc") == null) ? string.Empty : xp.Attribute("IDesc").Value;
                p.IIDesc = (xp.Attribute("IIDesc") == null) ? string.Empty : xp.Attribute("IIDesc").Value;
                p.Desc1 = (xp.Attribute("Desc1") == null) ? string.Empty : xp.Attribute("Desc1").Value;
                p.Desc2 = (xp.Attribute("Desc2") == null) ? string.Empty : xp.Attribute("Desc2").Value;
                p.Material = (xp.Attribute("Material") == null) ? string.Empty : xp.Attribute("Material").Value;
                p.MatEdgeUp = (xp.Attribute("MatEdgeUp") == null) ? string.Empty : xp.Attribute("MatEdgeUp").Value;
                p.MatEdgeLo = (xp.Attribute("MatEdgeLo") == null) ? string.Empty : xp.Attribute("MatEdgeLo").Value;
                p.MatEdgeL = (xp.Attribute("MatEdgeL") == null) ? string.Empty : xp.Attribute("MatEdgeL").Value;
                p.MatEdgeR = (xp.Attribute("MatEdgeR") == null) ? string.Empty : xp.Attribute("MatEdgeR").Value;
                p.CabHeigth = (xp.Attribute("CabHeigth") == null) ? 0 : double.Parse(xp.Attribute("CabHeigth").Value);
                p.CabDepth = (xp.Attribute("CabDepth") == null) ? 0 : double.Parse(xp.Attribute("CabDepth").Value);
                p.CabDesc = (xp.Attribute("CabDesc") == null) ? string.Empty : xp.Attribute("CabDesc").Value;
                p.Draw_1 = (xp.Attribute("Draw_1") == null) ? string.Empty : xp.Attribute("Draw_1").Value;
                p.Draw_2 = (xp.Attribute("Draw_2") == null) ? string.Empty : xp.Attribute("Draw_2").Value;
                p.Draw_3 = (xp.Attribute("Draw_3") == null) ? string.Empty : xp.Attribute("Draw_3").Value;
                p.Draw_4 = (xp.Attribute("Draw_4") == null) ? string.Empty : xp.Attribute("Draw_4").Value;
                p.InfoDraw_1 = (xp.Attribute("InfoDraw_1") == null) ? string.Empty : xp.Attribute("InfoDraw_1").Value;
                p.InfoDraw_2 = (xp.Attribute("InfoDraw_2") == null) ? string.Empty : xp.Attribute("InfoDraw_2").Value;
                p.InfoDraw_3 = (xp.Attribute("InfoDraw_3") == null) ? string.Empty : xp.Attribute("InfoDraw_3").Value;
                p.InfoDraw_4 = (xp.Attribute("InfoDraw_4") == null) ? string.Empty : xp.Attribute("InfoDraw_4").Value;
                p.SizeNo = (xp.Attribute("SizeNo") == null) ? 0 : int.Parse(xp.Attribute("SizeNo").Value);
                Parts.Add(p);
            }
            return Parts;
        }
    }
    public enum Grian
    {
        HGrain,
        VGrain,
        NGrain
    }

}
